GNU Multiple Precision Arithmetic Library

GNU Multiple Precision Arithmetic Library
Developer(s) The GNU Project
Initial release 1991 (1991)[1]
Stable release 5.0.2 / May 8, 2011; 9 months ago (2011-05-08)
Written in C
Operating system Cross-platform
Type Mathematical software
License LGPL
Website http://gmplib.org/

The GNU Multiple Precision Arithmetic Library, also known as GMP, is a free library for arbitrary-precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. There are no practical limits to the precision except the ones implied by the available memory in the machine GMP runs on (operand dimension limit is 231 bits on 32-bit machines and 237 bits on 64-bit machines[2]). GMP has a rich set of functions, and the functions have a regular interface. The basic interface is for C but wrappers exist for other languages including C++, C#, OCaml, Perl, PHP, and Python. In the past, the Kaffe Java virtual machine used GMP to support Java built-in arbitrary precision arithmetic. This feature has been removed from recent releases, causing protests from people who claim that they used Kaffe solely for the speed benefits afforded by GMP.[3] As a result, GMP support has been added to GNU Classpath.[4]

The main target applications of GMP are cryptography applications and research, Internet security applications, and computer algebra systems.

GMP aims to be faster than any other bignum library for all operand sizes. Some important factors towards this end are:

The first GMP release was made in 1991. It is continually developed and maintained.[1] The current release is 5.0.2.

GMP is part of the GNU project (although the fact that its website is not on gnu.org might cause confusion), and is distributed under the GNU LGPL.

GMP is used for integer arithmetic in many computer algebra systems such as Mathematica[5] and Maple.[6]

GMP is required for building GCC.[7]

Contents

Example

Here is an example of C code showing the use of the GMP library to multiply and print large numbers:

#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
 
int main(void)
{
 mpz_t x;
 mpz_t y;
 mpz_t result;
 
 mpz_init(x);
 mpz_init(y);
 mpz_init(result);
 
 mpz_set_str(x, "7612058254738945", 10);
 mpz_set_str(y, "9263591128439081", 10);
 
 mpz_mul(result, x, y);
 gmp_printf("\n    %Zd\n*\n    %Zd\n--------------------\n%Zd\n\n", x, y, result);
 return EXIT_SUCCESS;
}

This code calculates the value of 7612058254738945 × 9263591128439081.

Compiling and running this program gives this result. (You need to use the -lgmp flag if compiling under Unix-type systems.)

    7612058254738945
*
    9263591128439081
--------------------
70514995317761165008628990709545

Criticism

GMP has been criticized for its perceived lackluster support of Microsoft Windows and Microsoft Visual Studio.[8][9]

Language bindings

Library Name Language License
GNU Multi-Precision Library C / C++ LGPL
Math::GMP Perl
GNU Multi-Precision Library for .NET C# / .NET LGPL
General Multiprecision Python Project Python
The RubyGems project Ruby
GNU Multi-Precision Library for PHP PHP PHP License
GNU Multi-Precision Routines for SBCL Common Lisp
Ch GMP Ch
Glasgow Haskell Compiler
(The implementation of Integer
is basically a binding to GMP)
Haskell BSD

See also

References

External links